/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedbean.Production;

import entity.Inventory;
import entity.MaterialRequired;
import entity.Product;
import entity.RawMaterial;
import entity.TrackingItem;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import managedbean.UserSessionManagerBean;
import session.stateless.LogSessionBeanLocal;
import session.stateless.ProductSessionBeanLocal;
import session.stateless.WarehouseSessionBeanLocal;

/**
 *
 * @author Wx
 */
@ManagedBean(name = "productManagerBean")
@RequestScoped
public class ProductManagerBean implements Serializable {

    @EJB
    ProductSessionBeanLocal productSessionBeanLocal;
    @EJB
    LogSessionBeanLocal logSessionBeanLocal;
    @EJB
    WarehouseSessionBeanLocal warehouseSessionBeanLocal;
    @ManagedProperty(value = "#{userSessionManagerBean}")
    private UserSessionManagerBean userSessionManagerBean;
    private String loadAddRawMaterial;
    private String loadAddProduct;
    private String loadManageRawMaterials;
    private String loadManageProducts;
    private String loadUpdateProduct;
    private String loadUpdateRawMaterial;
    private List<RawMaterial> rawMaterials = new ArrayList<RawMaterial>();
    private RawMaterial selectedRawMaterial;
    private List<Product> products = new ArrayList<Product>();
    private Product selectedProduct;
    private MaterialRequired selectedMaterialRequired;
    //RawMaterial
    private Long rmId;
    private String rmName;
    private String rmDescription;
    private Integer shelfLife;
    private Integer leadTime;
    private Integer lotSize;
    private String rmStatus;
    //Product
    private String code;
    private String pName;
    private String pDescription;
    private String status;
    private Double price;
    private Double weight;
    private Integer capacityPerHour;
    private List<MaterialRequired> materialRequired = new ArrayList<MaterialRequired>();
    //MaterialRequired
    private Double materialWeight;
    private RawMaterial rawMaterial = new RawMaterial();
    private Boolean isDiscontinued;
    private Boolean isDiscontinued2;

    /** Creates a new instance of ProductManagerBean */
    public ProductManagerBean() {
    }

    public void updateARawMaterial(ActionEvent event) {
        try {
            RawMaterial temp = productSessionBeanLocal.getRawMaterialByName(rmName, rmId);

            if (temp == null) {
                if (rmStatus != null && !rmStatus.equals("")) {
                    selectedRawMaterial.setName(rmName);
                    selectedRawMaterial.setDescription(rmDescription);
                    selectedRawMaterial.setShelfLife(shelfLife);
                    selectedRawMaterial.setLotSize(lotSize);
                    selectedRawMaterial.setLeadTime(leadTime);
                    selectedRawMaterial.setStatus(rmStatus);

                    productSessionBeanLocal.updateRawMaterial(selectedRawMaterial);

                    FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                            + getUserSessionManagerBean().getServerName() + ":"
                            + getUserSessionManagerBean().getServerPort()
                            + "/MerlionERP-war/Web_Production/searchRawMaterials.xhtml"); //redirect to searchRawMaterials.xhtml
                } else {
                    FacesContext.getCurrentInstance().addMessage(null,
                            new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please select a status before continuing.", ""));
                }
            } else {
                FacesContext.getCurrentInstance().addMessage(null,
                        new FacesMessage(FacesMessage.SEVERITY_ERROR, "There is already an existing raw material with the same name.", ""));
            }
        } catch (Exception ex) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, ex.toString(), ""));
        }
    }

    public void updateRawMaterial(ActionEvent event) {
        try {
            if (selectedRawMaterial != null) {
                userSessionManagerBean.setSelectedRawMaterial(selectedRawMaterial);

                FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                        + getUserSessionManagerBean().getServerName() + ":"
                        + getUserSessionManagerBean().getServerPort()
                        + "/MerlionERP-war/Web_Production/updateRawMaterial.xhtml"); //redirect to updateRawMaterial.xhtml
            } else {
                FacesContext.getCurrentInstance().addMessage(null,
                        new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please select a raw material before continuing.", ""));
            }
        } catch (Exception ex) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, ex.toString(), ""));
        }
    }

    public void removeRawMaterial(ActionEvent event) {
        try {
            if (selectedRawMaterial != null) {
                List<Product> temp = productSessionBeanLocal.getProducts();

                String inUseList = "";
                Boolean stillInUse = false;
                for (Product p : temp) {
                    for (MaterialRequired mr : p.getMaterialRequired()) {
                        if (mr.getRawMaterial().getId() == selectedRawMaterial.getId()) {
                            stillInUse = true;

                            inUseList += p.getName() + ", ";
                        }
                    }
                }

                if (!stillInUse) {
                    if (!selectedRawMaterial.getStatus().equals("Discontinued")) {
                        selectedRawMaterial.setStatus("Discontinued");

                        productSessionBeanLocal.updateRawMaterial(selectedRawMaterial);

                        FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                                + getUserSessionManagerBean().getServerName() + ":"
                                + getUserSessionManagerBean().getServerPort()
                                + "/MerlionERP-war/Web_Production/searchRawMaterials.xhtml"); //redirect to searchRawMaterials.xhtml
                    } else {
                        FacesContext.getCurrentInstance().addMessage(null,
                                new FacesMessage(FacesMessage.SEVERITY_ERROR, "The selected raw material has already been removed from the warehouse", ""));
                    }
                } else {
                    FacesContext.getCurrentInstance().addMessage(null,
                            new FacesMessage(FacesMessage.SEVERITY_ERROR, "Selected raw material is still in use, "
                            + "please remove it from the relevant product's BOM before continuing."
                            + " Product(s) still using this raw material are: " + inUseList, ""));
                }
            } else {
                FacesContext.getCurrentInstance().addMessage(null,
                        new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please select a raw material before continuing.", ""));
            }
        } catch (Exception ex) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, ex.toString(), ""));
        }
    }

    public void removeProduct(ActionEvent event) {
        try {
            if (selectedProduct != null) {
                if (!selectedProduct.getStatus().equals("Discontinued")) {
                    selectedProduct.setStatus("Discontinued");

                    productSessionBeanLocal.updateProduct(selectedProduct);

                    FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                            + getUserSessionManagerBean().getServerName() + ":"
                            + getUserSessionManagerBean().getServerPort()
                            + "/MerlionERP-war/Web_Production/searchProducts.xhtml"); //redirect to searchProducts.xhtml
                } else {
                    FacesContext.getCurrentInstance().addMessage(null,
                            new FacesMessage(FacesMessage.SEVERITY_ERROR, "The selected product has already been discontinued.", ""));
                }
            } else {
                FacesContext.getCurrentInstance().addMessage(null,
                        new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please select a product before continuing.", ""));
            }
        } catch (Exception ex) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, ex.toString(), ""));
        }
    }

    public void deleteProductMaterial(ActionEvent event) {
        try {
            if (selectedMaterialRequired != null) {
                productSessionBeanLocal.deleteProductMaterial(selectedProduct.getCode(), selectedMaterialRequired.getId());

                selectedProduct = productSessionBeanLocal.getProduct(selectedProduct.getCode());
                selectedProduct.setCapacityPerHour(capacityPerHour);
                selectedProduct.setDescription(pDescription);
                selectedProduct.setName(pName);
                selectedProduct.setPrice(price);
                selectedProduct.setStatus(status);
                selectedProduct.setWeight(weight);

                userSessionManagerBean.setSelectedProduct(selectedProduct);

                FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                        + getUserSessionManagerBean().getServerName() + ":"
                        + getUserSessionManagerBean().getServerPort()
                        + "/MerlionERP-war/Web_Production/updateProduct.xhtml"); //redirect to updateProduct.xhtml
            } else {
                FacesContext.getCurrentInstance().addMessage(null,
                        new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please select a material to delete before continuing.", ""));
            }
        } catch (Exception ex) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, ex.toString(), ""));
        }
    }

    public void addProductMaterial(ActionEvent event) {
        try {
            if (rawMaterial.getId() != null) {
                if (materialWeight > 0) {
                    List<MaterialRequired> temp = selectedProduct.getMaterialRequired();

                    Boolean exist = false;
                    for (MaterialRequired mr : temp) {
                        if (mr.getRawMaterial().getId() == rawMaterial.getId()) {
                            exist = true; //material to add already is already in the product's material list

                            break;
                        }
                    }

                    if (!exist) { //if material to add does not exist in the product's material list
                        rawMaterial = productSessionBeanLocal.getRawMaterial(rawMaterial.getId());

                        MaterialRequired temp2 = new MaterialRequired(materialWeight, rawMaterial);

                        productSessionBeanLocal.updateProduct(selectedProduct.getCode(), temp2);

                        selectedProduct = productSessionBeanLocal.getProduct(selectedProduct.getCode());
                        selectedProduct.setCapacityPerHour(capacityPerHour);
                        selectedProduct.setDescription(pDescription);
                        selectedProduct.setName(pName);
                        selectedProduct.setPrice(price);
                        selectedProduct.setStatus(status);
                        selectedProduct.setWeight(weight);

                        userSessionManagerBean.setSelectedProduct(selectedProduct);

                        FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                                + getUserSessionManagerBean().getServerName() + ":"
                                + getUserSessionManagerBean().getServerPort()
                                + "/MerlionERP-war/Web_Production/updateProduct.xhtml"); //redirect to updateProduct.xhtml
                    } else { //if material to add already exists in the product's material list
                        FacesContext.getCurrentInstance().addMessage(null,
                                new FacesMessage(FacesMessage.SEVERITY_ERROR, "The material to add already exists in the product's material list.", ""));
                    }
                } else {
                    FacesContext.getCurrentInstance().addMessage(null,
                            new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please enter a figure of more than 0 for material weight.", ""));
                }
            } else {
                FacesContext.getCurrentInstance().addMessage(null,
                        new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please select a raw material to add.", ""));
            }
        } catch (Exception ex) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, ex.toString(), ""));
        }
    }

    public void updateAProduct(ActionEvent event) {
        try {
            Product temp = productSessionBeanLocal.getProductByName(pName, code);

            if (temp == null) {
                if (status != null && !status.equals("")) {

                    selectedProduct.setCode(code);
                    selectedProduct.setCapacityPerHour(capacityPerHour);
                    selectedProduct.setDescription(pDescription);
                    selectedProduct.setName(pName);
                    selectedProduct.setPrice(price);
                    selectedProduct.setStatus(status);
                    selectedProduct.setWeight(weight);

                    productSessionBeanLocal.updateProduct(selectedProduct);

                    FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                            + getUserSessionManagerBean().getServerName() + ":"
                            + getUserSessionManagerBean().getServerPort()
                            + "/MerlionERP-war/Web_Production/searchProducts.xhtml"); //redirect to searchProducts.xhtml
                } else {
                    FacesContext.getCurrentInstance().addMessage(null,
                            new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please select a status for this product.", ""));
                }
            } else {
                FacesContext.getCurrentInstance().addMessage(null,
                        new FacesMessage(FacesMessage.SEVERITY_ERROR, "There is already an existing product with the same name.", ""));
            }
        } catch (Exception ex) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, ex.toString(), ""));
        }
    }

    public void updateProduct(ActionEvent event) {
        try {
            if (selectedProduct != null) {
                userSessionManagerBean.setSelectedProduct(selectedProduct);

                FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                        + getUserSessionManagerBean().getServerName() + ":"
                        + getUserSessionManagerBean().getServerPort()
                        + "/MerlionERP-war/Web_Production/updateProduct.xhtml"); //redirect to updateProduct.xhtml
            } else {
                FacesContext.getCurrentInstance().addMessage(null,
                        new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please select a product before continuing.", ""));
            }
        } catch (Exception ex) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, ex.toString(), ""));
        }
    }

    public void addAProduct(ActionEvent event) {
        try {
            Product temp = productSessionBeanLocal.getProduct(code, pName);

            if ((temp != null && temp.getStatus().equals("Discontinued")) || (temp == null)) {
                if (!temp.getCode().equals(code)) {
                    List<MaterialRequired> temp2 = new ArrayList<MaterialRequired>();

                    Product product = new Product(code, pName, "Pending", pDescription, price, weight, capacityPerHour, temp2);

                    productSessionBeanLocal.addProduct(product);

                    temp = productSessionBeanLocal.getProduct(code, pName);

                    Inventory inventory = new Inventory(0.0, temp, null, new ArrayList<TrackingItem>());

                    productSessionBeanLocal.addInventoryRecord(inventory);

                    //redirect to success page
                    ArrayList<String> al = new ArrayList<String>();
                    al.add("Product");
                    al.add("You have successfully added the product.");
                    al.add("Click on the link to to ");
                    al.add("continue");
                    al.add("Web_Production/searchProducts.xhtml");
                    userSessionManagerBean.setSelectedItem(al);

                    logSessionBeanLocal.addLog("Add product", "product created: " + userSessionManagerBean.getUserId(), "addProduct.xhtml", userSessionManagerBean.getUserId());

                    FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                            + userSessionManagerBean.getServerName() + ":"
                            + userSessionManagerBean.getServerPort()
                            + "/MerlionERP-war/success.xhtml");
                } else {
                    FacesContext.getCurrentInstance().addMessage(null,
                            new FacesMessage(FacesMessage.SEVERITY_ERROR, "A product with the same code already exists.", ""));
                }
            } else {
                FacesContext.getCurrentInstance().addMessage(null,
                        new FacesMessage(FacesMessage.SEVERITY_ERROR, "A product with the same code or name already exists.", ""));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, ex.toString(), ""));
        }
    }

    public void addProduct(ActionEvent event) {
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                    + getUserSessionManagerBean().getServerName() + ":"
                    + getUserSessionManagerBean().getServerPort()
                    + "/MerlionERP-war/Web_Production/addProduct.xhtml"); //redirect to addProduct.xhtml
        } catch (Exception ex) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, ex.toString(), ""));
            ex.printStackTrace();
        }
    }

    public void back(ActionEvent event) {
        try {
            if (event.getComponent().getId().equals("btnBackFromAddRawMaterial")) {
                FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                        + getUserSessionManagerBean().getServerName() + ":"
                        + getUserSessionManagerBean().getServerPort()
                        + "/MerlionERP-war/Web_Production/searchRawMaterials.xhtml"); //redirect to searchRawMaterials.xhtml
            } else if (event.getComponent().getId().equals("btnBackFromAddProduct")) {
                FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                        + getUserSessionManagerBean().getServerName() + ":"
                        + getUserSessionManagerBean().getServerPort()
                        + "/MerlionERP-war/Web_Production/searchProducts.xhtml"); //redirect to searchProducts.xhtml
            } else if (event.getComponent().getId().equals("btnBackFromUpdateProduct")) {
                FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                        + getUserSessionManagerBean().getServerName() + ":"
                        + getUserSessionManagerBean().getServerPort()
                        + "/MerlionERP-war/Web_Production/searchProducts.xhtml"); //redirect to searchProducts.xhtml
            } else if (event.getComponent().getId().equals("btnBackFromUpdateRawMaterial")) {
                FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                        + getUserSessionManagerBean().getServerName() + ":"
                        + getUserSessionManagerBean().getServerPort()
                        + "/MerlionERP-war/Web_Production/searchRawMaterials.xhtml"); //redirect to searchRawMaterials.xhtml
            }
        } catch (Exception ex) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, ex.toString(), ""));
            ex.printStackTrace();
        }
    }

    public void addRawMaterial(ActionEvent event) {
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                    + getUserSessionManagerBean().getServerName() + ":"
                    + getUserSessionManagerBean().getServerPort()
                    + "/MerlionERP-war/Web_Production/addRawMaterial.xhtml"); //redirect to addRawMaterial.xhtml
        } catch (Exception ex) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, ex.toString(), ""));
            ex.printStackTrace();
        }
    }

    public void addARawMaterial(ActionEvent event) {
        try {
            RawMaterial temp = productSessionBeanLocal.getRawMaterial(rmName);

            if (temp == null) { //if raw material does not exist
                RawMaterial rawMaterial = new RawMaterial(rmName, rmDescription, shelfLife, leadTime, lotSize);

                productSessionBeanLocal.addRawMaterial(rawMaterial);

                temp = productSessionBeanLocal.getRawMaterial(rmName);

                Inventory inventory = new Inventory(0.0, null, temp, new ArrayList<TrackingItem>());

                productSessionBeanLocal.addInventoryRecord(inventory);

                //redirect to success page
                ArrayList<String> al = new ArrayList<String>();
                al.add("Raw material");
                al.add("You have successfully added the raw material.");
                al.add("Click on the link to to ");
                al.add("continue");
                al.add("Web_Production/searchRawMaterials.xhtml");
                userSessionManagerBean.setSelectedItem(al);

                logSessionBeanLocal.addLog("Add raw material", "Raw material created: " + userSessionManagerBean.getUserId(), "addRawMaterial.xhtml", userSessionManagerBean.getUserId());

                FacesContext.getCurrentInstance().getExternalContext().redirect("http://"
                        + userSessionManagerBean.getServerName() + ":"
                        + userSessionManagerBean.getServerPort()
                        + "/MerlionERP-war/success.xhtml");
            } else { //if raw material exists
                FacesContext.getCurrentInstance().addMessage(null,
                        new FacesMessage(FacesMessage.SEVERITY_ERROR, "Raw material already exists.", ""));
            }
        } catch (Exception ex) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, ex.toString(), ""));
            ex.printStackTrace();
        }
    }

    /**
     * @return the loadAddRawMaterial
     */
    public String getLoadAddRawMaterial() {
        //pending

        return null;
    }

    /**
     * @param loadAddRawMaterial the loadAddRawMaterial to set
     */
    public void setLoadAddRawMaterial(String loadAddRawMaterial) {
        this.loadAddRawMaterial = loadAddRawMaterial;
    }

    /**
     * @return the loadAddProduct
     */
    public String getLoadAddProduct() {
        //pending

        return null;
    }

    /**
     * @param loadAddProduct the loadAddProduct to set
     */
    public void setLoadAddProduct(String loadAddProduct) {
        this.loadAddProduct = loadAddProduct;
    }

    /**
     * @return the loadManageRawMaterials
     */
    public String getLoadManageRawMaterials() {
        rawMaterials = productSessionBeanLocal.getRawMaterials();

        selectedProduct = null;

        return null;
    }

    /**
     * @param loadManageRawMaterials the loadManageRawMaterials to set
     */
    public void setLoadManageRawMaterials(String loadManageRawMaterials) {
        this.loadManageRawMaterials = loadManageRawMaterials;
    }

    /**
     * @return the rawMaterials
     */
    public List<RawMaterial> getRawMaterials() {
        return rawMaterials;
    }

    /**
     * @param rawMaterials the rawMaterials to set
     */
    public void setRawMaterials(List<RawMaterial> rawMaterials) {
        this.rawMaterials = rawMaterials;
    }

    /**
     * @return the rmName
     */
    public String getRmName() {
        return rmName;
    }

    /**
     * @param rmName the rmName to set
     */
    public void setRmName(String rmName) {
        this.rmName = rmName;
    }

    /**
     * @return the rmDescription
     */
    public String getRmDescription() {
        return rmDescription;
    }

    /**
     * @param rmDescription the rmDescription to set
     */
    public void setRmDescription(String rmDescription) {
        this.rmDescription = rmDescription;
    }

    /**
     * @return the shelfLife
     */
    public Integer getShelfLife() {
        return shelfLife;
    }

    /**
     * @param shelfLife the shelfLife to set
     */
    public void setShelfLife(Integer shelfLife) {
        this.shelfLife = shelfLife;
    }

    /**
     * @return the leadTime
     */
    public Integer getLeadTime() {
        return leadTime;
    }

    /**
     * @param leadTime the leadTime to set
     */
    public void setLeadTime(Integer leadTime) {
        this.leadTime = leadTime;
    }

    /**
     * @return the selectedRawMaterial
     */
    public RawMaterial getSelectedRawMaterial() {
        return selectedRawMaterial;
    }

    /**
     * @param selectedRawMaterial the selectedRawMaterial to set
     */
    public void setSelectedRawMaterial(RawMaterial selectedRawMaterial) {
        this.selectedRawMaterial = selectedRawMaterial;
    }

    /**
     * @return the userSessionManagerBean
     */
    public UserSessionManagerBean getUserSessionManagerBean() {
        return userSessionManagerBean;
    }

    /**
     * @param userSessionManagerBean the userSessionManagerBean to set
     */
    public void setUserSessionManagerBean(UserSessionManagerBean userSessionManagerBean) {
        this.userSessionManagerBean = userSessionManagerBean;
    }

    /**
     * @return the lotSize
     */
    public Integer getLotSize() {
        return lotSize;
    }

    /**
     * @param lotSize the lotSize to set
     */
    public void setLotSize(Integer lotSize) {
        this.lotSize = lotSize;
    }

    /**
     * @return the loadManageProducts
     */
    public String getLoadManageProducts() {
        products = productSessionBeanLocal.getProducts();

        return null;
    }

    /**
     * @param loadManageProducts the loadManageProducts to set
     */
    public void setLoadManageProducts(String loadManageProducts) {
        this.loadManageProducts = loadManageProducts;
    }

    /**
     * @return the products
     */
    public List<Product> getProducts() {
        return products;
    }

    /**
     * @param products the products to set
     */
    public void setProducts(List<Product> products) {
        this.products = products;
    }

    /**
     * @return the selectedProduct
     */
    public Product getSelectedProduct() {
        return selectedProduct;
    }

    /**
     * @param selectedProduct the selectedProduct to set
     */
    public void setSelectedProduct(Product selectedProduct) {
        this.selectedProduct = selectedProduct;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @return the pName
     */
    public String getpName() {
        return pName;
    }

    /**
     * @param pName the pName to set
     */
    public void setpName(String pName) {
        this.pName = pName;
    }

    /**
     * @return the pDescription
     */
    public String getpDescription() {
        return pDescription;
    }

    /**
     * @param pDescription the pDescription to set
     */
    public void setpDescription(String pDescription) {
        this.pDescription = pDescription;
    }

    /**
     * @return the status
     */
    public String getStatus() {
        return status;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(String status) {
        this.status = status;
    }

    /**
     * @return the price
     */
    public Double getPrice() {
        return price;
    }

    /**
     * @param price the price to set
     */
    public void setPrice(Double price) {
        this.price = price;
    }

    /**
     * @return the weight
     */
    public Double getWeight() {
        return weight;
    }

    /**
     * @param weight the weight to set
     */
    public void setWeight(Double weight) {
        this.weight = weight;
    }

    /**
     * @return the capacityPerHour
     */
    public Integer getCapacityPerHour() {
        return capacityPerHour;
    }

    /**
     * @param capacityPerHour the capacityPerHour to set
     */
    public void setCapacityPerHour(Integer capacityPerHour) {
        this.capacityPerHour = capacityPerHour;
    }

    /**
     * @return the loadUpdateProduct
     */
    public String getLoadUpdateProduct() {
        selectedProduct = userSessionManagerBean.getSelectedProduct();

        code = selectedProduct.getCode();
        pName = selectedProduct.getName();
        status = selectedProduct.getStatus();
        price = selectedProduct.getPrice();
        pDescription = selectedProduct.getDescription();
        weight = selectedProduct.getWeight();
        capacityPerHour = selectedProduct.getCapacityPerHour();
        materialRequired = selectedProduct.getMaterialRequired();

        rawMaterials = productSessionBeanLocal.getRawMaterials();

        materialWeight = 0.00;

        if (status.equals("Discontinued")) {
            isDiscontinued = true;
        } else {
            isDiscontinued = false;
        }

        return null;
    }

    /**
     * @param loadUpdateProduct the loadUpdateProduct to set
     */
    public void setLoadUpdateProduct(String loadUpdateProduct) {
        this.loadUpdateProduct = loadUpdateProduct;
    }

    /**
     * @return the materialRequired
     */
    public List<MaterialRequired> getMaterialRequired() {
        return materialRequired;
    }

    /**
     * @param materialRequired the materialRequired to set
     */
    public void setMaterialRequired(List<MaterialRequired> materialRequired) {
        this.materialRequired = materialRequired;
    }

    /**
     * @return the selectedMaterialRequired
     */
    public MaterialRequired getSelectedMaterialRequired() {
        return selectedMaterialRequired;
    }

    /**
     * @param selectedMaterialRequired the selectedMaterialRequired to set
     */
    public void setSelectedMaterialRequired(MaterialRequired selectedMaterialRequired) {
        this.selectedMaterialRequired = selectedMaterialRequired;
    }

    /**
     * @return the materialWeight
     */
    public Double getMaterialWeight() {
        return materialWeight;
    }

    /**
     * @param materialWeight the materialWeight to set
     */
    public void setMaterialWeight(Double materialWeight) {
        this.materialWeight = materialWeight;
    }

    /**
     * @return the rawMaterial
     */
    public RawMaterial getRawMaterial() {
        return rawMaterial;
    }

    /**
     * @param rawMaterial the rawMaterial to set
     */
    public void setRawMaterial(RawMaterial rawMaterial) {
        this.rawMaterial = rawMaterial;
    }

    /**
     * @return the loadUpdateRawMaterial
     */
    public String getLoadUpdateRawMaterial() {
        selectedRawMaterial = userSessionManagerBean.getSelectedRawMaterial();

        rmId = selectedRawMaterial.getId();
        rmName = selectedRawMaterial.getName();
        rmDescription = selectedRawMaterial.getDescription();
        shelfLife = selectedRawMaterial.getShelfLife();
        leadTime = selectedRawMaterial.getLeadTime();
        lotSize = selectedRawMaterial.getLotSize();
        rmStatus = selectedRawMaterial.getStatus();

        if (rmStatus.equals("Discontinued")) {
            isDiscontinued2 = true;
        } else {
            isDiscontinued2 = false;
        }

        return null;
    }

    /**
     * @param loadUpdateRawMaterial the loadUpdateRawMaterial to set
     */
    public void setLoadUpdateRawMaterial(String loadUpdateRawMaterial) {
        this.loadUpdateRawMaterial = loadUpdateRawMaterial;
    }

    /**
     * @return the rmId
     */
    public Long getRmId() {
        return rmId;
    }

    /**
     * @param rmId the rmId to set
     */
    public void setRmId(Long rmId) {
        this.rmId = rmId;
    }

    /**
     * @return the isDiscontinued
     */
    public Boolean getIsDiscontinued() {
        return isDiscontinued;
    }

    /**
     * @param isDiscontinued the isDiscontinued to set
     */
    public void setIsDiscontinued(Boolean isDiscontinued) {
        this.isDiscontinued = isDiscontinued;
    }

    /**
     * @return the rmStatus
     */
    public String getRmStatus() {
        return rmStatus;
    }

    /**
     * @param rmStatus the rmStatus to set
     */
    public void setRmStatus(String rmStatus) {
        this.rmStatus = rmStatus;
    }

    /**
     * @return the isDiscontinued2
     */
    public Boolean getIsDiscontinued2() {
        return isDiscontinued2;
    }

    /**
     * @param isDiscontinued2 the isDiscontinued2 to set
     */
    public void setIsDiscontinued2(Boolean isDiscontinued2) {
        this.isDiscontinued2 = isDiscontinued2;
    }
}
